package producersConsumersTests.bypassersCount;


public class Schedule {
	private volatile long entries[][], exits[][];
	private int insertersNum;
	private int removersNum;
	private volatile static Schedule sched;

	public static void init(int insertersNum, int removersNum) {
		sched = new Schedule(insertersNum, removersNum);
	}

	public static Schedule get() {
		return sched;
	}

	private Schedule(int insertersNum, int removersNum) {
		entries = new long[insertersNum][insertersNum];
		exits = new long[removersNum][removersNum];
		this.insertersNum = insertersNum;
		this.removersNum = removersNum;
		for (int i = 0; i < insertersNum; i++)
			for (int j = 0; j < insertersNum; j++)
				entries[i][j] = 0;
		for (int i = 0; i < removersNum; i++)
			for (int j = 0; j < removersNum; j++)
				exits[i][j] = 0;
	}

	public void updateEntryRow(int id, int row) {
		for (int i = 0; i < insertersNum; i++)
			if (i != id)
				this.entries[row][i] = entries[row][id];
	}

	public void updateExitRow(int id, int row) {
		for (int i = 0; i < removersNum; i++)
			if (i != id)
				this.exits[row][i] = exits[row][id];
	}

	public long getEntry(int id, int id2) {
		return entries[id][id2];
	}

	public long getExit(int id, int id2) {
		return exits[id][id2];
	}

	public void incrementEntranceEntry(int id, int id2) {
		this.entries[id][id2]++;
	}

	public void incrementExitEntry(int id, int id2) {
		this.exits[id][id2]++;
	}
}
